Skip to content

Add shell aliases feature to devbox.json#2835

Merged
mikeland73 merged 4 commits into
mainfrom
claude/devbox-alias-feature-kitsM
Jun 1, 2026
Merged

Add shell aliases feature to devbox.json#2835
mikeland73 merged 4 commits into
mainfrom
claude/devbox-alias-feature-kitsM

Conversation

@mikeland73
Copy link
Copy Markdown
Collaborator

@mikeland73 mikeland73 commented May 31, 2026

Add a top-level aliases map to devbox.json that lets users define shell
aliases declaratively instead of hand-writing them in the init_hook.

{
  "shell": {
    "init_hook": "echo welcome"
  },
  "aliases": {
    "ll": "ls -la",
    "gs": "git status"
  }
}

In the interactive shell (devbox shell), aliases are injected after the
init hook is sourced, so they can rely on anything the hook sets up. They use
the shell's builtin alias command, which is compatible across bash, zsh, and
fish. Values are single-quoted and escaped per-shell so they are passed
verbatim.

Via devbox run, devbox run <alias> expands the alias to its command and
runs it (with any extra args passed through), mirroring how a shell expands an
alias in command position. This means aliases work without an interactive shell
— i.e. even when the init hook hasn't defined them.

Aliases merge across included plugins and the parent config, with the parent
overriding plugin-defined aliases (same precedence as env/scripts).

  • configfile: add top-level aliases field + validation (no empty/whitespace names, no empty commands)
  • config: add merged Aliases() accessor (root overrides included)
  • shell: render alias lines (sorted, escaped) into the shellrc after the init hook
  • devbox run: expand devbox run <alias> to the alias command
  • shellrc.tmpl / shellrc_fish.tmpl: emit aliases after hooks are sourced
  • schema: document the top-level aliases key
  • examples/plugins/local: plugin defines aliases, parent overrides one
  • tests: parsing, merging, plugin override (via the local example), rendering, escaping, validation, and devbox run <alias>

claude added 2 commits May 31, 2026 16:55
Add a shell.aliases map to devbox.json that lets users define shell
aliases declaratively instead of hand-writing them in the init_hook.

Aliases are injected into the devbox shell after the init hook is
sourced, so they can rely on anything the hook sets up. They use the
shell's builtin alias command, which is compatible across bash, zsh,
and fish. Values are single-quoted and escaped per-shell so they are
passed verbatim.

- configfile: add Aliases to shell config + accessor
- config: add merged Aliases() accessor (root overrides included)
- shell: render alias lines (sorted, escaped) into the shellrc
- shellrc.tmpl / shellrc_fish.tmpl: emit aliases after hooks are sourced
- schema: document shell.aliases
- tests for parsing, merging, rendering, and escaping
Promote aliases from shell.aliases to a top-level "aliases" key in
devbox.json. Behavior is unchanged: aliases are still injected into the
devbox shell after the init hook is sourced.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds declarative shell alias support to devbox configuration and renders configured aliases into generated shell startup files after the init hook.

Changes:

  • Adds alias storage/accessors in devconfig and merge behavior across included configs.
  • Renders deterministic, shell-escaped alias commands for POSIX shells and fish.
  • Updates schema and tests for alias parsing/rendering behavior.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internal/devconfig/configfile/file.go Adds alias configuration field to parsed config.
internal/devconfig/config.go Adds merged Aliases() accessor.
internal/devconfig/config_test.go Tests alias parsing and empty alias behavior.
internal/devbox/shell.go Generates sorted alias command lines with shell-specific quoting.
internal/devbox/shell_test.go Tests shellrc alias rendering and placement after hooks.
internal/devbox/shellrc.tmpl Emits aliases in POSIX shellrc template.
internal/devbox/shellrc_fish.tmpl Emits aliases in fish shellrc template.
.schema/devbox.schema.json Documents the new aliases configuration property.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .schema/devbox.schema.json
Comment thread internal/devbox/shell.go

lines := make([]string, 0, len(names))
for _, name := range names {
lines = append(lines, fmt.Sprintf("alias %s=%s", name, s.quoteAliasValue(aliases[name])))
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Added a validateAliases check (mirroring validateScripts) that runs at config load time and rejects aliases with empty/whitespace names or empty commands, so they can no longer render invalid alias syntax at shell startup. Fixed in 39c156a, with tests covering each invalid case.


Generated by Claude Code

@mikeland73 mikeland73 requested review from Lagoja and gcurtis May 31, 2026 17:23
Reject aliases with empty/whitespace names or empty commands at config
load time, so they can't render invalid shell syntax (e.g. "alias =..."
or "alias bad name=...") at shell startup. Mirrors script name
validation.
Make aliases defined in devbox.json runnable with `devbox run <alias>`,
not just inside the interactive shell. When the run target isn't a
script, it's expanded against the merged aliases (mirroring how a shell
expands an alias in command position), so aliases work even when the
init hook hasn't defined them. Arguments are passed through.

Also demonstrate plugin aliases + parent override in the local plugin
example, with a test asserting the merged result, plus a run testscript
exercising `devbox run <alias>` and argument passthrough.
@mikeland73 mikeland73 merged commit 35d57a3 into main Jun 1, 2026
24 checks passed
@mikeland73 mikeland73 deleted the claude/devbox-alias-feature-kitsM branch June 1, 2026 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants